package cn.hallele.leinsteining.mc.infrastructure.data.generator;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets;

import java.util.EnumSet;

/**
 * RandomGenerator
 *
 * @author anle5
 * @since 2024/8/4 20:32
 */
@Slf4j
public class RandomGenerator implements BeforeExecutionGenerator {
    /**
     * Generate a value.
     *
     * @param session      会话
     * @param owner        要存入的实体
     * @param currentValue 当前值
     * @param eventType    增？删？改？查？
     * @return The generated value
     */
    @Override
    public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType) {
        return System.currentTimeMillis();
    }

    /**
     * The {@linkplain EventType event types} for which this generator should be called
     * to produce a new value.
     * <p>
     * Identifier generators must return {@link EventTypeSets#INSERT_ONLY}.
     *
     * @return a set of {@link EventType}s.
     */
    @Override
    public EnumSet<EventType> getEventTypes() {
        return EventTypeSets.INSERT_ONLY;
    }
}